package com.pinxixi.content.mapper;

import com.pinxixi.framework.domain.content.Content;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ContentMapper {

    @Select("select id,category_id categoryId,title,url,pic,status,sort_order sortOrder from tb_content order by status desc,sort_order asc")
    List<Content> findAll();

    @Insert("insert into tb_content set category_id=#{categoryId},title=#{title},url=#{url},pic=#{pic},status=#{status},sort_order=#{sortOrder}")
    void add(Content content);

    @Select("select id,category_id categoryId,title,url,pic,status,sort_order sortOrder from tb_content where id=#{id}")
    Content findOne(Long id);

    @Update("update tb_content set category_id=#{categoryId},title=#{title},url=#{url},pic=#{pic},status=#{status},sort_order=#{sortOrder} where id=#{id}")
    void update(Content content);

    @Delete("delete from tb_content where id=#{id}")
    void delete(Long id);

    @Select("select id,category_id categoryId,title,url,pic,status,sort_order sortOrder from tb_content where category_id=#{categoryId} and status=1")
    List<Content> findContentByCategoryId(Long categoryId);
}

